//
//  AppDelegate+SLExtension.m
//  ECERP.CRM
//
//  Created by 刘思麟 on 2018/11/6.
//  Copyright © 2018 Mac. All rights reserved.
//

#import "AppDelegate+SLExtension.h"

NSString * Access_token;
NSString * merchantId;

@implementation AppDelegate (SLExtension)

- (UIWindow *)effectWindow {
    UIWindow * window = objc_getAssociatedObject(self, @"effectWindow");
    if (!window) {
        window = [UIWindow new];
        window.hidden = YES;
        window.backgroundColor = [ECCOLOR(0x010101) colorWithAlphaComponent:0.00001];
        objc_setAssociatedObject(self, @"effectWindow", window, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    return window;
}

- (void)showEffectWindow:(void (^)(UIWindow * _Nonnull))showBlock {
    WS(weakSelf, self);
    self.effectWindow.hidden = NO;
    [self.effectWindow makeKeyAndVisible];
    [UIView animateWithDuration:0.25 animations:^{
        weakSelf.effectWindow.backgroundColor = [ECCOLOR(0x010101) colorWithAlphaComponent:0.62];
    } completion:^(BOOL finished) {
        
    }];
    if (showBlock) {
        showBlock(self.effectWindow);
    }
}

- (void)hiddenEffectWindow:(void (^)(UIWindow * _Nonnull))hideBlock {
    WS(weakSelf, self);
    [UIView animateWithDuration:0.25 animations:^{
        weakSelf.effectWindow.backgroundColor = [ECCOLOR(0x010101) colorWithAlphaComponent:0.00001];
    } completion:^(BOOL finished) {
        weakSelf.effectWindow.hidden = YES;
    }];
    [self.effectWindow resignKeyWindow];
    if (hideBlock) {
        hideBlock(self.effectWindow);
    }
}

@end
